<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2014/12/17
 * Time: 20:03
 */

namespace Admin\Controller;

use Think\Controller;

class LoginController extends Controller
{
    public function  index()
    {
        if (!IS_POST) {
            $this->display();
            return;
        }
        //判断验证码输入是否正确
        $verify = new \Think\Verify();
        if (!$verify->check(I('post.code'))) {
            $this->error("验证码错误", U('/admin/login', '', ''), 1);
        }
        $username = I('post.username');
        $password = md5(I('post.password'));
        $model = M('admin');
        $user = $model->where(array('Username' => $username))->find();
        if (!$user) $this->error("用户名或密码错误", U('/admin/login', '', ''), 1);
        if ($user['Password'] != $password) $this->error("用户名或密码错误", U('/admin/login', '', ''), 1);
        session('uid', $user['ID']);
        session('username', $username);
        $this->success('登录成功!', U('/admin/index', '', ''), 1);
    }

    public function  logout()
    {
        session_unset();
        session_destroy();
        $this->success("退出成功!", U('/admin/login', '', ''), 1);
    }

    public function vf()
    {
        $Verify = new \Think\Verify();
        $Verify->entry();
    }
} 